home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / cbibcode.arc / CTRLBRK.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-05  |  822 b   |  41 lines

  1. #include <stdio.h>
  2. #include <dos.h>
  3. #include <setjmp.h>
  4.  
  5. int cbrk_handler(void);
  6. /* Buffer used by setjmp and longjmp */
  7. jmp_buf main_menu;
  8.  
  9. main()
  10. {
  11.     char input[80];
  12.     int choice=0;
  13. /* Install the Control-Break handler */
  14.     ctrlbrk(cbrk_handler);
  15.  
  16. /* Call 'setjmp' to set up for returning to this
  17.  * point after user presses Control-C */
  18.     if(setjmp(main_menu) != 0)
  19.     {
  20. /* Returning from a 'longjmp' -- print message */
  21.         printf("Interrupted...\n");
  22.     }
  23.  
  24. /* This is the main menu of the program */
  25.     printf("1 Loop endlessly...\n"
  26.         "anything else to exit\n\n"
  27.         "Enter Choice: ");
  28.     gets(input);
  29.     choice =atoi(input);
  30.     switch(choice)
  31.     {
  32.         case 1: for(;;) printf("Looping...\n");
  33.  
  34.         default: exit(0);
  35.     }
  36. }
  37. int cbrk_handler(void)
  38. {
  39. /* Return to the main menu */
  40.     longjmp(main_menu, 1);
  41. }